package cn.iocoder.yudao.module.social.api.interaction;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.social.api.interaction.dto.InteractionReqDTO;
import cn.iocoder.yudao.module.social.api.interaction.dto.InteractionRespDTO;
import cn.iocoder.yudao.module.social.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

/**
 * RPC 服务 - 互动管理
 *
 * @author 芋道源码
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 互动管理")
public interface InteractionApi {

    String PREFIX = ApiConstants.PREFIX + "/interaction";

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建互动")
    CommonResult<Long> createInteraction(@RequestBody InteractionReqDTO reqDTO);

    @DeleteMapping(PREFIX + "/delete")
    @Operation(summary = "删除互动")
    @Parameter(name = "id", description = "互动编号", example = "1024", required = true)
    CommonResult<Boolean> deleteInteraction(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "通过互动 ID 查询互动")
    @Parameter(name = "id", description = "互动编号", example = "1024", required = true)
    CommonResult<InteractionRespDTO> getInteraction(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "批量查询互动信息")
    @Parameter(name = "ids", description = "互动编号数组", example = "1,2", required = true)
    CommonResult<List<InteractionRespDTO>> getInteractionList(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/list-by-content")
    @Operation(summary = "根据内容查询互动列表")
    @Parameter(name = "contentId", description = "内容编号", example = "1024", required = true)
    CommonResult<List<InteractionRespDTO>> getInteractionListByContent(@RequestParam("contentId") Long contentId);

    @GetMapping(PREFIX + "/list-by-user")
    @Operation(summary = "根据用户查询互动列表")
    @Parameter(name = "userId", description = "用户编号", example = "1024", required = true)
    CommonResult<List<InteractionRespDTO>> getInteractionListByUser(@RequestParam("userId") Long userId);

    @GetMapping(PREFIX + "/list-by-type")
    @Operation(summary = "根据类型查询互动列表")
    @Parameter(name = "type", description = "互动类型", example = "comment", required = true)
    CommonResult<List<InteractionRespDTO>> getInteractionListByType(@RequestParam("type") String type);

    /**
     * 批量查询互动 MAP
     *
     * @param ids 互动编号列表
     * @return 互动 MAP
     */
    default Map<Long, InteractionRespDTO> getInteractionMap(Collection<Long> ids) {
        return convertMap(getInteractionList(ids).getCheckedData(), InteractionRespDTO::getId);
    }

}
